{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "操作方式,登录qmt,选择行情加交易选,择极简模式\n",
      "作者:小果\n",
      "作者微信:15117320079\n",
      "作者微信公众号:数据分析与运用\n",
      "公众号链接:https://mp.weixin.qq.com/s/rxGJpZYxdUIHitjvI-US1A\n",
      "作者知识星球:金融量化交易研究院 id:51340043\n",
      "链接qmt\n",
      "作者微信15117320079**********************授权码正确,到期日2024-06-28 剩余天数40******************\n",
      "qmt链接成功\n",
      "0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(<qmt_trader.xtquant.xttrader.XtQuantTrader at 0x1e51273cdf0>,\n",
       " <qmt_trader.xtquant.xttype.StockAccount at 0x1e526982bb0>)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from qmt_trader.qmt_trader import qmt_trader\n",
    "from qmt_trader.xtquant.xttype import StockAccount\n",
    "from qmt_trader.xtquant import xtconstant\n",
    "trader=qmt_trader(path= r'D:/国金QMT交易端模拟/userdata_mini',\n",
    "                  session_id = 123456,account='55011917',account_type='STOCK',\n",
    "                  is_slippage=True,slippage=0.01)\n",
    "#链接\n",
    "trader.connect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'831754445'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#随机id\n",
    "trader.random_session_id()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17.020000000000003"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#设置滑点\n",
    "trader.select_slippage(stock='600031',price=17.01,trader_type='buy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17.0"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trader.select_slippage(stock='600031',price=17.01,trader_type='sell')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "周末\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#检查是否是交易时间\n",
    "trader.check_is_trader_date()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'stock'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#检查数据类型\n",
    "trader.select_data_type(stock='600031')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'600031.SH'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#调整股票代码\n",
    "trader.adjust_stock(stock='600031')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "允许买入600031 可用现金19988646.87大于买入金额17010.0 价格17.01 数量1000\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#检查是否可以买入\n",
    "trader.check_stock_is_av_buy(stock='600031',price=17.01,amount=1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "不允许卖出持股不足：600031 持股600 卖出1000\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#检查是否可以卖出\n",
    "trader.check_stock_is_av_sell(stock='600031',amount=1000)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n",
      "交易类型23 代码600031.SH 价格17.020000000000003 数量100 订单编号1082133489\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1082133489"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#买入\n",
    "trader.order_stock(stock_code='600031.SH', order_type=xtconstant.STOCK_BUY,\n",
    "     order_volume=100,price_type=xtconstant.FIX_PRICE,price=17.01,strategy_name='',order_remark='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n",
      "交易类型23 代码600031.SH 价格17.020000000000003 数量100 订单编号35\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "35"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#兼容同花顺的买入函数\n",
    "trader.buy(security='600031.SH', order_type=xtconstant.STOCK_BUY,\n",
    "                    amount=100,price_type=xtconstant.FIX_PRICE,price=17.01,strategy_name='',order_remark='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n",
      "on_order_stock_async_response\n",
      "55011917 1082133490 35\n",
      "on order_error callback\n",
      "1082133490 -61 限价买入 [SH600031] [AGENT] [COUNTER] [120141][证券交易未初始化]\n",
      "[init_date=20240517,curr_date=20240519]\n",
      "\n",
      "交易类型24 代码600031.SH 价格19.99 数量100 订单编号1082133491\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1082133491"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#兼容同花顺的卖出函数\n",
    "trader.sell(security='600031.SH', order_type=xtconstant.STOCK_SELL,\n",
    "                    amount=100,price_type=xtconstant.FIX_PRICE,price=20,strategy_name='',order_remark='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "131810.SZ实时数据 {'131810.SZ': {'timetag': '20240517 15:29:48', 'lastPrice': 1.7, 'open': 1.75, 'high': 1.85, 'low': 1.655, 'lastClose': 1.645, 'amount': 182689422000, 'volume': 182689422, 'pvolume': 1826894220, 'stockStatus': 0, 'openInt': 13, 'settlementPrice': 0, 'lastSettlementPrice': 0, 'askPrice': [1.705, 1.71, 1.72, 1.725, 1.745], 'bidPrice': [1.7, 1.65, 1.6, 1.205, 1.005], 'askVol': [635, 1537, 17, 43, 5], 'bidVol': [262181, 31400, 100000, 800, 400]}}\n",
      "None\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('交易成功', '国债逆回购交易类型24 代码131810.SZ 价格1.7 数量99000 订单编号1082133492')"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#国债逆回购\n",
    "trader.reverse_repurchase_of_treasury_bonds(security='131810.SZ',buy_ratio=0.005, order_type=xtconstant.STOCK_SELL\n",
    "                                             ,price_type=xtconstant.FIX_PRICE,strategy_name='',order_remark='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'204001.SH': {'timetag': '20240517 15:29:57', 'lastPrice': 1.72, 'open': 1.785, 'high': 1.85, 'low': 1.685, 'lastClose': 1.655, 'amount': 1344468255000, 'volume': 1344468255, 'pvolume': 13444682550, 'stockStatus': 0, 'openInt': 13, 'settlementPrice': 0, 'lastSettlementPrice': 0, 'askPrice': [1.735, 1.75, 1.755, 1.76, 1.765], 'bidPrice': [1.72, 1.71, 1.705, 1.7, 1.655], 'askVol': [79, 1142, 620, 18656, 11481], 'bidVol': [8605, 11786, 30667, 611400, 20000]}}\n",
      "{'131810.SZ': {'timetag': '20240517 15:29:48', 'lastPrice': 1.7, 'open': 1.75, 'high': 1.85, 'low': 1.655, 'lastClose': 1.645, 'amount': 182689422000, 'volume': 182689422, 'pvolume': 1826894220, 'stockStatus': 0, 'openInt': 13, 'settlementPrice': 0, 'lastSettlementPrice': 0, 'askPrice': [1.705, 1.71, 1.72, 1.725, 1.745], 'bidPrice': [1.7, 1.65, 1.6, 1.205, 1.005], 'askVol': [635, 1537, 17, 43, 5], 'bidVol': [262181, 31400, 100000, 800, 400]}}\n",
      "204001.SH 1.72\n",
      "None\n",
      "交易类型24 代码204001.SH 价格1.71 数量9000 订单编号1082133493\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('交易成功', '国债逆回购交易类型 代码204001.SH 价格1.72 数量9000 订单编号1082133493')"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#国债逆回购1\n",
    "trader.reverse_repurchase_of_treasury_bonds_1(buy_ratio=0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n",
      "交易类型23 代码600031.SH 价格20.01 数量100 订单编号49\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "49"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对股票进行异步下单操作，异步下单接口如果正常返回了下单请求序号seq，会收到on_order_stock_async_response的委托反馈\n",
    "trader.order_stock_async(stock_code='600031.SH', order_type=xtconstant.STOCK_BUY,\n",
    "                    order_volume=100,price_type=xtconstant.FIX_PRICE,price=20,strategy_name='',order_remark='')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "on_order_stock_async_response\n",
      "55011917 1082133494 49\n",
      "on order_error callback\n",
      "1082133494 -61 限价买入 [SH600031] [AGENT] [COUNTER] [120141][证券交易未初始化]\n",
      "[init_date=20240517,curr_date=20240519]\n",
      "\n",
      "委托已完成撤单失败\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    ":param account: 证券账号\n",
    ":param order_id: 委托编号, 报单时返回的编号\n",
    ":return: 返回撤单成功或者失败, 0:成功,  -1:委托已完成撤单失败, -2:未找到对应委托编号撤单失败, -3:账号未登陆撤单失败\n",
    "'''\n",
    "trader.cancel_order_stock(order_id=12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "51"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        * 释义 \n",
    "        - 根据订单编号对委托进行异步撤单操作\n",
    "        * 参数\n",
    "        - account - StockAccount  资金账号 \n",
    "        - order_id - int 下单接口返回的订单编号\n",
    "        * 返回 \n",
    "        - 返回撤单请求序号, 成功委托后的撤单请求序号为大于0的正整数, 如果为-1表示委托失败\n",
    "        * 备注\n",
    "        - 如果失败，则通过撤单失败主推接口返回撤单失败信息\n",
    "        '''\n",
    "trader.cancel_order_stock_async(order_id=12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'账号类型': 2,\n",
       " '资金账户': '55011917',\n",
       " '可用金额': 19988646.87,\n",
       " '冻结金额': 0.0,\n",
       " '持仓市值': 10230.0,\n",
       " '总资产': 19998876.87}"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        :param account: 证券账号\n",
    "            :return: 返回当前证券账号的资产数据\n",
    "        '''\n",
    "trader.query_stock_asset()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>账号类型</th>\n",
       "      <th>资金账户</th>\n",
       "      <th>可用金额</th>\n",
       "      <th>冻结金额</th>\n",
       "      <th>持仓市值</th>\n",
       "      <th>总资产</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>55011917</td>\n",
       "      <td>19988646.87</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10230.0</td>\n",
       "      <td>19998876.87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   账号类型      资金账户         可用金额  冻结金额     持仓市值          总资产\n",
       "0     2  55011917  19988646.87   0.0  10230.0  19998876.87"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "对接同花顺\n",
    "'''\n",
    "trader.balance()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        当日委托\n",
    "         :param account: 证券账号\n",
    "        :param cancelable_only: 仅查询可撤委托\n",
    "        :return: 返回当日所有委托的委托对象组成的list\n",
    "        '''\n",
    "trader.query_stock_orders()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        对接同花顺\n",
    "        今天委托\n",
    "        '''\n",
    "trader.today_entrusts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'正常'"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        检查股票是否涨停跌停\n",
    "        '''\n",
    "trader.get_check_stock_is_limit_down(stock='600031')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n",
      "今天没有委托3/委托已经成交\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(0, '没有委托/委托已经成交')"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "检查没有成交的当日委托\n",
    "'''\n",
    "trader.get_check_not_trader_today_entrusts(stock='600031',trader_type='buy',data_type='数量')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n",
      "今天没有委托3/委托已经成交\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(0, '没有委托/委托已经成交')"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "检查没有成交的当日委托\n",
    "'''\n",
    "trader.get_check_not_trader_today_entrusts(stock='600031',trader_type='sell',data_type='数量')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n",
      "今天没有委托3/委托已经成交\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(0, '没有委托/委托已经成交')"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "检查没有成交的当日委托\n",
    "'''\n",
    "trader.get_check_not_trader_today_entrusts(stock='600031',trader_type='buy',data_type='金额')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n",
      "今天没有委托3/委托已经成交\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(0, '没有委托/委托已经成交')"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "检查没有成交的当日委托\n",
    "'''\n",
    "trader.get_check_not_trader_today_entrusts(stock='600031',trader_type='sell',data_type='金额')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "        通过证券代码来撤单\n",
    "        类型cancel_type=all/buy/sell/one\n",
    "        在有多个单时候选择怎么样撤单num=0/all\n",
    "        '''\n",
    "try:\n",
    "    trader.cancel_order_stock_async_by_code(cancel_type='all',stock='600031',num='all')\n",
    "except:\n",
    "    pass\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "成交数量: 0\n",
      "今日没有成交\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        当日成交\n",
    "        '''\n",
    "trader.query_stock_trades()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "成交数量: 0\n",
      "今日没有成交\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        对接同花顺\n",
    "        今日成交\n",
    "        '''\n",
    "trader.today_trades()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "<qmt_trader.xtquant.xtpythonclient.XtPosition object at 0x000001E526796670>\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>账号类型</th>\n",
       "      <th>资金账号</th>\n",
       "      <th>证券代码</th>\n",
       "      <th>持仓数量</th>\n",
       "      <th>可用数量</th>\n",
       "      <th>平均建仓成本</th>\n",
       "      <th>市值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>55011917</td>\n",
       "      <td>600031</td>\n",
       "      <td>600</td>\n",
       "      <td>600</td>\n",
       "      <td>18.922</td>\n",
       "      <td>10230.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   账号类型      资金账号    证券代码  持仓数量  可用数量  平均建仓成本       市值\n",
       "0     2  55011917  600031   600   600  18.922  10230.0"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        查询账户所有的持仓\n",
    "        '''\n",
    "trader.query_stock_positions()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>账号类型</th>\n",
       "      <th>资金账号</th>\n",
       "      <th>证券代码</th>\n",
       "      <th>股票余额</th>\n",
       "      <th>可用余额</th>\n",
       "      <th>成本价</th>\n",
       "      <th>参考成本价</th>\n",
       "      <th>市值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>55011917</td>\n",
       "      <td>600031</td>\n",
       "      <td>600</td>\n",
       "      <td>600</td>\n",
       "      <td>18.922</td>\n",
       "      <td>18.922</td>\n",
       "      <td>10230.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   账号类型      资金账号    证券代码  股票余额  可用余额     成本价   参考成本价       市值\n",
       "0     2  55011917  600031   600   600  18.922  18.922  10230.0"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        对接同花顺\n",
    "        持股\n",
    "        '''\n",
    "trader.position()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "没有持股\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trader.query_stock_position(stock_code='600031')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "没有数据/处理出现错误\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>品种名称</th>\n",
       "      <th>品种类型</th>\n",
       "      <th>最小申购额度</th>\n",
       "      <th>最大申购额度</th>\n",
       "      <th>申购日期</th>\n",
       "      <th>发行价</th>\n",
       "      <th>证券代码</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [品种名称, 品种类型, 最小申购额度, 最大申购额度, 申购日期, 发行价, 证券代码]\n",
       "Index: []"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        获取股票新可转债ipo数据\n",
    "        dict 新股新债信息数据集\n",
    "\n",
    "        { stock1: info1, stock2: info2, ... }\n",
    "\n",
    "        stock - str 品种代码，例如 '301208.SZ'\n",
    "        info - dict 新股信息\n",
    "        name - str 品种名称\n",
    "        type - str 品种类型\n",
    "        STOCK - 股票，BOND - 债券\n",
    "        minPurchaseNum / maxPurchaseNum - int 最小 / 最大申购额度\n",
    "        单位为股（股票）/ 张（债券）\n",
    "        purchaseDate - str 申购日期\n",
    "        issue\n",
    "'''\n",
    "trader.query_stock_ipo_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "55011917\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "'str' object has no attribute 'account_type'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[69], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtrader\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mquery_stock_new_purchase_limit\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mc:\\Users\\lxg123456\\Desktop\\综合自定义交易系统v5.5.7.6.4_可转债自定义改正禄得算法源代码\\qmt_trader\\qmt_trader.py:1165\u001b[0m, in \u001b[0;36mquery_stock_new_purchase_limit\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m   1163\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maccount)\n\u001b[0;32m   1164\u001b[0m df\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mxt_trader\u001b[38;5;241m.\u001b[39mquery_new_purchase_limit(account\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maccount)\n\u001b[1;32m-> 1165\u001b[0m \u001b[38;5;28mprint\u001b[39m(df)\n",
      "File \u001b[1;32mc:\\Users\\lxg123456\\Desktop\\综合自定义交易系统v5.5.7.6.4_可转债自定义改正禄得算法源代码\\qmt_trader\\xtquant\\xttrader.py:922\u001b[0m, in \u001b[0;36mXtQuantTrader.query_new_purchase_limit\u001b[1;34m(self, account)\u001b[0m\n\u001b[0;32m    917\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    918\u001b[0m \u001b[38;5;124;03m:param account: 证券账号\u001b[39;00m\n\u001b[0;32m    919\u001b[0m \u001b[38;5;124;03m:return: 返回账户新股申购额度数据\u001b[39;00m\n\u001b[0;32m    920\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    921\u001b[0m req \u001b[38;5;241m=\u001b[39m XTQC\u001b[38;5;241m.\u001b[39mQueryNewPurchaseLimitReq()\n\u001b[1;32m--> 922\u001b[0m req\u001b[38;5;241m.\u001b[39mm_nAccountType \u001b[38;5;241m=\u001b[39m \u001b[43maccount\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43maccount_type\u001b[49m\n\u001b[0;32m    923\u001b[0m req\u001b[38;5;241m.\u001b[39mm_strAccountID \u001b[38;5;241m=\u001b[39m account\u001b[38;5;241m.\u001b[39maccount_id\n\u001b[0;32m    925\u001b[0m seq \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39masync_client\u001b[38;5;241m.\u001b[39mnextSeq()\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'account_type'"
     ]
    }
   ],
   "source": [
    "trader.query_stock_new_purchase_limit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "目标数量下单501018 目标数量1000 持有数量0 可以用数量0 需要买入数量1000\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('buy', 1000, 12)"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        目标数量下单\n",
    "        stock: 标的代码\n",
    "        amount: 期望的最终数量\n",
    "        price:价格\n",
    "        trader_type针对买入账户没有持股的股票，一般不改动\n",
    "'''\n",
    "trader.order_target_volume(stock='501018',amount=1000,price=12)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "按金额下单501018 交易类型buy 可用资金19988646.87大于 下单金额1000  下单数量700\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('buy', 700, 1.33)"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        按金额下单\n",
    "        stock: 证券代码\n",
    "        value下单金额\n",
    "        value大于0买入，小0卖出\n",
    "        prive交易的的价格\n",
    "        '''\n",
    "trader.order_value(stock='501018',value=1000,price=1.33,trader_type='buy')\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        调整数量\n",
    "        '''\n",
    "trader.adjust_amount(stock='600031',amount=110)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "目标价值下单501018 目标价值1000 可用资金19988646.87大于买卖资金931.0 目标数量700 持有数量0 可用数量0 买入差额700\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('buy', 700, 1.33)"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        目标价值下单\n",
    "        stock: 股票名字\n",
    "        value: 股票价值，value = 最新价 * 手数 * 保证金率（股票为1） * 乘数（股票为100）\n",
    "        prive交易的的价格\n",
    "        '''\n",
    "trader.order_target_value(stock='501018',value=1000,price=1.33)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "委托数量 0\n",
      "目前没有委托\n",
      "今天没有委托3/委托已经成交\n",
      "百分比交易501018 下单类型buy 百分比0.1 下单数量1503600 可以资金19988646.87大于目标资金1999887.6870000002 买入数量1503600\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('buy', 1503600, 1.33)"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        百分比交易\n",
    "        percent下单百分比\n",
    "        '''\n",
    "trader.order_percent(stock='501018',percent=0.1,price=1.33,trader_type='buy')\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "委托数量 0\n",
      "目前没有委托\n",
      "今天没有委托3/委托已经成交\n",
      "501018账户没有持股不支持交易类型sell\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('', 0, 1.33)"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        百分比交易\n",
    "        percent下单百分比\n",
    "        '''\n",
    "trader.order_percent(stock='501018',percent=0.1,price=1.33,trader_type='sell')\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "目标百分比下单501018 目标百分比0.1 目标数量1503674.952631579 可以资金19988646.87大于目标资金1999887.6870000002 持有数量0 可用数量0 买入差额1503600\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('buy', 1503600, 1.33)"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        目标百分比下单\n",
    "        '''\n",
    "trader.order_target_percent(stock='501018',target_percent=0.1,price=1.33)\n",
    "       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "目标百分比下单501018 目标百分比0 目标数量0.0 可以资金19988646.87目标资金0.0 持有数量0 可用数量0 买入差额0小于10不下单\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('', 0, 1.33)"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        目标百分比下单\n",
    "        '''\n",
    "trader.order_target_percent(stock='501018',target_percent=0,price=1.33)\n",
    "       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "持仓数量: 1\n",
      "目标数量下单501018 目标数量1503674.952631579 持有数量0 可以用数量0 需要买入数量1503600\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('buy', 1503600, 1.33)"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        目标百分比下单数量模式\n",
    "        '''\n",
    "trader.order_target_percent_volume(stock='501018',target_percent=0.1,price=1.33)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "持仓数量: 1\n",
      "目标数量下单501018 目标数量0.0 持有数量0 可以用数量0 需要卖出数量0.0等于0不交易\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('', 0, 1.33)"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        目标百分比下单数量模式\n",
    "        '''\n",
    "trader.order_target_percent_volume(stock='501018',target_percent=0,price=1.33)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "持仓数量: 1\n",
      "目标价值下单501018 目标价值1999887.6870000002 可用资金19988646.87大于买卖资金1999788.0 目标数量1503600 持有数量0 可用数量0 买入差额1503600\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('buy', 1503600, 1.33)"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        目标百分比下单金额模式\n",
    "        '''\n",
    "trader.order_target_percent_value(stock='501018',target_percent=0.1,price=1.33)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "持仓数量: 1\n",
      "目标价值下单501018 目标价值0.0 目标数量0 等于持有数量0 可用数量0 卖出差额0不下单\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('', 0, 1.33)"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        目标百分比下单金额模式\n",
    "        '''\n",
    "trader.order_target_percent_value(stock='501018',target_percent=0,price=1.33)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓数量: 1\n",
      "一键清仓600031 持有数量600 可用数量600 卖出数量600\n",
      "None\n",
      "交易类型24 代码600031.SH 价格17.04 数量600 订单编号1082133580\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "        一键清仓\n",
    "        '''\n",
    "trader.one_click_clearance()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n",
      "一键撤单 没有委托\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "        一键撤单全部\n",
    "        \"\"\"\n",
    "trader.one_click_cancel_order_all()\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n",
      "一键撤单 没有委托\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "        一键撤单全部买入委托\n",
    "        \"\"\"\n",
    "trader.one_click_cancel_order_buy()\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n",
      "一键撤单 没有委托\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "        一键撤单全部卖出委托\n",
    "        \"\"\"\n",
    "trader.one_click_cancel_order_sell()\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n",
      "一键撤单 没有委托\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "        一键撤单个股全部买入委托\n",
    "        \"\"\"\n",
    "trader.one_click_cancel_order_buy_by_stock(stock='600031')\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "委托数量 0\n",
      "目前没有委托\n",
      "今天没有委托3/委托已经成交\n",
      "持仓数量: 1\n",
      "委托数量 0\n",
      "目前没有委托\n",
      "今天没有委托3/委托已经成交\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('buy', 1000, 2.475)"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        检查模块资金分配\n",
    "        data_type='数量'/资金\n",
    "        trader_type='buy',交易类型\n",
    "        amount=1000,每次交易的数量股\n",
    "        limit_volume=2000,单一标的持股限制\n",
    "        value=2000,每次交易金额\n",
    "        limit_value=4000,单一标的金额限制\n",
    "        stock='501018',代码\n",
    "        price=2.475交易的价格\n",
    "        '''\n",
    "trader.check_av_target_trader(data_type='数量',trader_type='buy',amount=1000,limit_volume=2000,\n",
    "                value=2000,limit_value=4000,stock='501018',price=2.475)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "没有数据\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        账户数据\n",
    "        释义\n",
    "        查询信用资金账号对应的资产\n",
    "        参数\n",
    "        account - StockAccount 资金账号\n",
    "        返回\n",
    "        该信用账户对应的资产对象XtCreditDetail组成的list或者None\n",
    "        备注\n",
    "        None表示查询失败\n",
    "        通常情况下一个资金账号只有一个详细信息数据\n",
    "        示例\n",
    "        查询信用资金账号1208970161对应的资产信息\n",
    "        '''\n",
    "trader.query_credit_detail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "没有负债合约\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        释义\n",
    "        查询资金账号对应的负债合约\n",
    "        参数\n",
    "        account - StockAccount 资金账号\n",
    "        返回\n",
    "        该账户对应的负债合约对象StkCompacts组成的list或者None\n",
    "        备注\n",
    "        None表示查询失败或者负债合约列表为空\n",
    "        示例\n",
    "        查询信用资金账号1208970161对应的负债合约\n",
    "        '''\n",
    "trader.query_stk_compacts()\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "没有融资融券标的\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        释义\n",
    "        查询资金账号对应的融资融券标的\n",
    "        参数\n",
    "        account - StockAccount 资金账号\n",
    "        返回\n",
    "        该账户对应的融资融券标的对象CreditSubjects组成的list或者None\n",
    "        备注\n",
    "        None表示查询失败或者融资融券标的列表为空\n",
    "        示例\n",
    "        查询信用资金账号1208970161对应的融资融券标的\n",
    "        '''\n",
    "trader.query_credit_subjects()\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "没有可融券数据\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        释义\n",
    "        查询资金账号对应的可融券数据\n",
    "        参数\n",
    "        account - StockAccount 资金账号\n",
    "        返回\n",
    "        该账户对应的可融券数据对象CreditSloCode组成的list或者None\n",
    "        备注\n",
    "        None表示查询失败或者可融券数据列表为空\n",
    "        示例\n",
    "        查询\n",
    "'''\n",
    "trader.query_credit_slo_code()\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "没有对应的标的担保品\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "        释义\n",
    "        查询资金账号对应的标的担保品\n",
    "        参数\n",
    "        account - StockAccount 资金账号\n",
    "        返回\n",
    "        该账户对应的标的担保品对象CreditAssure组成的list或者None\n",
    "        备注\n",
    "        None表示查询失败或者标的担保品列表为空\n",
    "        示例\n",
    "        查询信用资金账号1208970161对应的标的担保品\n",
    "        '''\n",
    "trader.query_credit_assure()\n",
    "        "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  },
  "orig_nbformat": 2
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
